package com.gdd.videos.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.EventListener;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author zhangh     
 * @version V1.0.0
 * @projectName parent
 * @title     SwaggerConfig   
 * @package    com.gdd.videos.common  
 * @date   2019/9/3 9:44  
 * @explain swagger2的配置内容仅仅就是需要创建一个Docket实例
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .pathMapping("/")
                .apiInfo(apiInfo())
                .select()
                // controller接口路径
                .apis(RequestHandlerSelectors.basePackage("com.gdd.videos.mini_api.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("使用swagger2构建的Gdd微信小视频后的后端api接口文档")
                .description("微信小程序后端接口")
                .version("0.0.1")
                .build(); // 这部分信息其实可以自定义到配置文件中读取
    }

}
